﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;
using ASER.DataAccess.BaseDataAccess;
using ASER.DataEntity.Security;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace ASER.DataAccess.Security
{
    class Sys_menuDataAccess : BaseDataAccess.BaseDataAccess<Sys_MenuEntity>
    {
        public List<Sys_MenuEntity> GetMenus(Sys_OperatorEntity user)
        {
            List<Sys_MenuEntity> Result = null;
            string sqlText = @"SELECT A.* FROM Sys_Menu A JOIN Sys_MenuPosition B ON A.MenuID=B.MenuID
                           JOIN Sys_OperatorPosition C ON B.PositionCode = C.PositonCode
                            WHERE C.UserCode=@UserCode AND LEFT(MenuSeq ,11)='s0001.e0001'";
            Database db = DatabaseFactory.CreateDatabase("Platform");
            using (DbCommand Command = db.GetSqlStringCommand(sqlText))
            {
                db.AddInParameter(Command, "@UserCode", DbType.String, user.UserCode);
                IDataReader Reader = db.ExecuteReader(Command);
                try
                {
                    Result = FillDataListGeneric(Reader);
                }
                finally
                {
                    Reader.Close();
                    Reader.Dispose();
                }
            }
            return Result;
        }
    }
}
